<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <c:import url="../../header.jsp"/>
    <link rel="stylesheet" type="text/css"
          href="https://tstatic.dgg.net/static/plugs/ztree/css/zTreeStyle/zTreeStyle.css"/>
    <link rel="stylesheet" type="text/css"
          href="${basePath}/static/css/production.css?v=${version}"/>
</head>
<body>
<div class="body-main">
    <div class="table-conter">
        <a href="javascript:void(0)" class="layui-btn layui-btn-mini" onclick="OpenCreateTabPage()">新增证书配置</a>
    </div>
    <div class="table-body">
        <!--表格 start-->
        <table id="template" class="cell-border crm-table columnsHidden dataTable">
            <thead>
            <tr>
                <th width="20px">序号</th>
                <th width="80px">证书类型</th>
                <th width="300px">证书专业</th>
                <th width="100px">证书等级</th>
                <th width="50px">匹配周期</th>
                <th width="80px">工作日/自然日</th>
                <th width="50px">扣罚数量</th>
                <th width="50px">单位</th>
                <th width="50px">操作</th>
            </tr>
            </thead>
        </table>
        <!--表格 end-->
    </div>
</div>
<c:import url="../../footer.jsp"/>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function () {
        //初始化dataTable列表
        var table = $('#template').dataTableExtend({
            "ajax": {"url": "${basePath}/zs/matching/query_list.do", "type": "post"},
            "fnServerParams": function (aoData) {
                //搜索条件
            },
            "pageLength": 20,//每页显示的条数默认是10条，有特殊业务需要显示不同条数的列表才应该加入该参数
            "scrollX":"true",
            "fixedColumns":   {//锁定列，只有开启scrollX时才生效
                "leftColumns": 2,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "aoColumns": [
                {
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return meta.row + 1;

                    }
                }, {
                    "orderable": false,
                    "data": "certificateType",
                }, {
                    "orderable": false,
                    "data": "certificateSpecialtys",
                    "render":function (data, type, full, meta) {
                        var htm='<p class="line2 remarkAlertClass" style="min-width: 300px" title="'+data+'">'+data+'</p>';
                        return htm;
                    }
                }, {
                    "orderable": false,
                    "data": "certificateLevel"
                },{
                    "orderable": false,
                    "data": "matchingTime"
                },
                {
                    "orderable": false,
                    "data": "isNatureWorkDay",
                    "render": function (d, type, r, meta) {
                        if (d == 1) {
                            return "工作日";
                        }
                        if (d == 2) {
                            return "自然日";
                        }
                    }
                },{
                    "orderable": false,
                    "data": "punishCount"
                }, {
                    "orderable": false,
                    "data": "unit",
                    "render": function (d, type, r, meta) {
                        if (d == 1) {
                            return "金额";
                        }
                        if (d == 2) {
                            return "操行分";
                        }
                    }
                },{
                    "orderable": false,
                    "data": "id",
                    "render": function (d, type, r, meta) {
                        var result = "";
                        result += '<a href=\'javascript:void(0)\' class="layui-table-link"  onclick="openEditTabPage(\'' + r.id + '\')" /><span style="color: #0066ff ">编辑</a>&nbsp;&nbsp;';
                        result += '<a href=\'javascript:void(0)\' class="layui-table-link"  onclick="deleteMatching(\'' + r.id + '\')" /><span style="color: #0066ff ">删除</a>';
                        return result;
                    }
                }]
        });

    });
    /**
     * 打开新增配置页面
     */
    function OpenCreateTabPage() {
        $.post(sysInfo.basePath + "/zs/matching/finecreate_tabpage.html", function (data) {
            dgg.Open({
                title: '新增证书配置',
                content: data,
                area: '30%',
                btn: ["确定", "取消"],
                yes: function () {
                    matchingCreate();
                }, btn2: function () {

                }
            });
        }, 'html');

    }
    function matchingCreate() {
        var certificateType = $('[name="certificateType"]').val();
        var certificateSpecialtys = $('#certificateSpecialtys').val();
        var certificateLevel = $('[name="certificateLevel"]').val();
        var isNatureWorkDay = $('[name="isNatureWorkDay"]').val();
        var matchingTime = $('[name="matchingTime"]').val();
        var unit = $('[name="unit"]').val();
        var punishCount = $('[name="punishCount"]').val();
        if(checkAll(certificateSpecialtys)){
            DGG.Warning('选择了全部就不能选择其他证书专业！');
            return;
        }
        if(!certificateType){
            DGG.Warning('请选择证书类型！');
            return;
        }
        if(!certificateSpecialtys){
            DGG.Warning('请选择证书专业！');
            return;
        }
        if(!certificateLevel){
            DGG.Warning('请选择证书等级！');
            return;
        }

        //判断业态是否选择到最下级
        /* var n = (busYtCode.split('_')).length - 1;
         if (n != 3) {
             DGG.Layer.message('请选择正确的业态！', {icon: '0'});
             return;
         }*/

        if(matchingTime<=0 || matchingTime>200 || !(/(^[1-9]\d*$)/.test(matchingTime))) {
            DGG.Warning("匹配周期大于0小于200的整数！");
            return false;
        }
        if(punishCount<=0 || punishCount>200 || !(/^[0-9]{1,3}(\.[0-9]{2}|\.[0-9]|)$/.test(punishCount))){
            DGG.Warning('扣罚数量大于0小于等于200的数字，可允许两位小数');
            return;
        }
        var params=$('#flowCreate').serializeArray();
        params.push({name:'certificateSpecialtys',value:certificateSpecialtys});
        params.push({name:'generalType',value:'${generalType}'});
        DGG.Confire("确定新增证书配置？", '新增证书配置', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: params,
                url: sysInfo.basePath + '/zs/matching/save.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！')
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable1();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Errors('保存失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }
    function reloadTable1() {
        $('#template').dataTableExtend("reload");
    }
    function deleteMatching(id) {
        DGG.Confire("确定删除配置？", '删除证书配置', function () {
            DGG.loading();
            $.ajax({
                type: 'POST',
                async: true,
                data: {"id": id},
                url: sysInfo.basePath + '/zs/matching/delete.do',
                dataType: 'JSON',
                success: function (data) {
                    DGG.loading('close');
                    if (data.code == 0) {
                        DGG.Succeed('操作成功！')
                        setTimeout(function () {
                            layer.closeAll();
                        }, 1000);
                        reloadTable1();
                    } else {
                        DGG.Errors(data.msg);
                    }
                },
                error: function () {
                    DGG.Errors('删除失败，请联系管理员！！');
                }
            })
        }, function () {
        })
    }
        /**
         * 打开编辑流程页面
         */
        function openEditTabPage(id) {
            DGG.loading();
            $.post(sysInfo.basePath + "/zs/matching/fineedit_tabpage.html", {id:id}, function (data) {
                dgg.Open({
                    title: '编辑证书匹配设置',
                    content: data,
                    area: '30%',
                    btn: ["确定", "取消"],
                    yes: function () {
                        matchingEdit()
                    }
                });
            }, 'html');

        }
        function matchingEdit(){
            var certificateType = $('[name="certificateType"]').val();
            var certificateSpecialtys = $('#certificateSpecialtys').val();
            var certificateLevel = $('[name="certificateLevel"]').val();
            var isNatureWorkDay = $('[name="isNatureWorkDay"]').val();
            var matchingTime = $('[name="matchingTime"]').val();
            var unit = $('[name="unit"]').val();
            var punishCount = $('[name="punishCount"]').val();
            if(checkAll(certificateSpecialtys)){
                DGG.Warning('选择了全部就不能选择其他证书专业！');
                return;
            }
            if(!certificateType){
                DGG.Warning('请选择证书类型！');
                return;
            }
            if(!certificateSpecialtys){
                DGG.Warning('请选择证书专业！');
                return;
            }
            if(!certificateLevel){
                DGG.Warning('请选择证书等级！');
                return;
            }

            //判断业态是否选择到最下级
            /* var n = (busYtCode.split('_')).length - 1;
             if (n != 3) {
                 DGG.Layer.message('请选择正确的业态！', {icon: '0'});
                 return;
             }*/

            if(matchingTime<=0 || matchingTime>200 || !(/(^[1-9]\d*$)/.test(matchingTime))) {
                DGG.Warning("匹配周期大于0小于200的整数！");
                return false;
            }
            if(punishCount<=0 || punishCount>200 || !(/^[0-9]{1,3}(\.[0-9]{2}|\.[0-9]|)$/.test(punishCount))){
                DGG.Warning('扣罚数量大于0小于等于200的数字，可允许两位小数');
                return;
            }
            var params=$('#flowCreate').serializeArray();
            params.push({name:'certificateSpecialtys',value:certificateSpecialtys});
            params.push({name:'generalType',value:'${generalType}'});
            DGG.Confire("确定修改证书配置？", '编辑证书配置', function () {
                DGG.loading();
                $.ajax({
                    type: 'POST',
                    async: true,
                    data: params,
                    url: sysInfo.basePath + '/zs/matching/edit.do',
                    dataType: 'JSON',
                    success: function (data) {
                        DGG.loading('close');
                        if (data.code == 0) {
                            DGG.Succeed('操作成功！')
                            setTimeout(function () {
                                layer.closeAll();
                            }, 1000);
                            reloadTable1();
                        } else {
                            DGG.Errors(data.msg);
                        }
                    },
                    error: function () {
                        DGG.Errors('保存失败，请联系管理员！！');
                    }
                })
            }, function () {
            })
        }
    function checkAll(certificateSpecialtys){
        if(certificateSpecialtys.indexOf("isAll") != -1){
            if(certificateSpecialtys.length>1){
                return true;
            }else{
                return false;
            }
        }
        return false;
    }

</script>
</body>
</html>